package concordia.comp6231.server;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

class UDPClient {
	public static String send(String host, int port, String data) throws Exception {
		DatagramSocket clientSocket = new DatagramSocket();
		InetAddress IPAddress = InetAddress.getByName(host);
		byte[] sendData = data.getBytes();
		byte[] receiveData = new byte[10240];
		DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
		clientSocket.send(sendPacket);
		DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
		clientSocket.receive(receivePacket);
		String result = new String(receivePacket.getData());
		System.out.println("FROM SERVER:" + result);
		clientSocket.close();
		return result;
	}
}